package net.lab1024.sa.admin.module.business.supercomputer.selecttablename.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import net.lab1024.sa.admin.module.business.supercomputer.selecttablename.service.SaveTableNamesService;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class SavaTableNameController {

    @Resource
    private SaveTableNamesService saveTableNamesService;

    @Operation(summary = "存储dateSource表的source_tablename字段")
    @GetMapping("/save-table-name/save/{tableName}/{sourceId}")
    @SaCheckPermission("save-table-name:save")
    public ResponseDTO<String> save(@PathVariable String tableName,@PathVariable Integer sourceId) {
        saveTableNamesService.saveTableNames(tableName, sourceId);
        return ResponseDTO.ok();
    }

    @Operation(summary = "根据数据源名获取表名")
    @GetMapping("/save-table-name/name/{sourceId}")
    @SaCheckPermission("save-table-name:name")
    public ResponseDTO<String> get(@PathVariable Integer sourceId) {
        return ResponseDTO.ok(saveTableNamesService.getTableNameBySourceName(sourceId));
    }
}
